package com.cqw.service;

import com.cqw.domain.Area;
import com.cqw.mapper.one.AreaMapper;
import com.cqw.mq.MqProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.*;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-04-15 10:40
 * @Description: ${Description}
 */
@Service
@Slf4j
public class AreaService {


    @Resource
    private AreaMapper areaMapper;

    @Autowired
    private MqProvider mqProvider;

    //线程池
    private static ExecutorService executorService = new ThreadPoolExecutor(5, 10, 100, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>(100));

    @PostConstruct
    public void init() {
        //删除数据
        //areaMapper.delete();
        //mqProvider.initArea();
    }


    public List<Area> getAreaList() {
        long start = System.currentTimeMillis();
        List<Area> list = areaMapper.selectAll();
        //组装数据
       /* try {
            TimeUnit.SECONDS.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        Future<Integer> submit = executorService.submit(this::init1);
        try {
            Integer integer = submit.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();
        System.out.println("消耗时间：" + (end - start));
        return null;
    }

    public int init1() {
        //删除数据
        try {
            TimeUnit.SECONDS.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return 1;
    }


}
